package com.ly.spring.jdbc.biz;


import com.ly.spring.jdbc.dao.AccountDao;
import com.ly.spring.jdbc.dao.OprecordDao;
import com.ly.spring.jdbc.entity.Oprecored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.net.BindException;

@Service
public class BankBiz {

    @Autowired
    AccountDao accountDao;
    @Autowired
    OprecordDao oprecordDao;

    @Transactional(rollbackFor = BizException.class,
            //rollbackFor  编译异常
            //noRollbackFor  运行异常
            noRollbackFor = ArithmeticException.class)
    public void deposit(long id, double money) throws BizException {
        Oprecored oprecored = new Oprecored();
        oprecored.setAid(id);
        oprecored.setOpmoney(money);
        oprecordDao.insert(oprecored);
        if (money > 5000){
            throw new BizException("存款金额大于5000");
        }
        //int i = 1/0;  //测试用
        accountDao.updateBalanceById(id,money);
    }


    public void withdraw(long id, double money) {

    }

    public void transfer(long id1,Long id2, double money) {

    }
}
